package cc.vv.btpartyjob.partymanager.activity

import android.text.TextUtils
import android.view.View
import android.view.WindowManager
import cc.vv.baselibrary.bean.base.BaseResponseObj
import cc.vv.baselibrary.util.LKToastUtil
import cc.vv.baselibrary.view.BaseTopBarView
import cc.vv.btpartyjob.partymanager.R
import cc.vv.btpartyjob.partymanager.delegate.ManagerBaseBinder
import cc.vv.btpartyjob.partymanager.delegate.SubmitPingJiaActivityDelegate
import cc.vv.btpartyjob.partymanager.moudel.resp.SubmitUnitReportResponseObj
import cc.vv.btpartyjob.partymanager.server.PartyManagerServer
import cc.vv.mvp.activity.BaseActivityMVP
import cc.vv.mvp.binder.BaseDataBinder

/**
 * 发布评价
 * Created by Chen.qi on 2018/10/29.
 */
class SubmitPingJiaActivity : BaseActivityMVP<SubmitPingJiaActivityDelegate>() {

    private var id: String? = null

    override fun initData() {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN)
        try {
            id = intent.getStringExtra("id")
        } catch (e: Exception) {
        }
        viewDelegate?.setTopBarTitle("发布评价")
    }

    override fun bindEvenListener() {
        viewDelegate?.setTitleBackBtnOnClick(object : BaseTopBarView.EventInterface {
            //返回
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {}
            override fun rightOnClick() {
            }
        })


        viewDelegate?.setOnClickListener(View.OnClickListener {
            //提交
            val pjContent = viewDelegate?.getPJContent()
            if (TextUtils.isEmpty(pjContent)) {
                LKToastUtil.showToastShort("请输入评价内容")
                return@OnClickListener
            }
            PartyManagerServer.addPingJia(id, pjContent)
        }, R.id.rl_aspPJ_submit)

    }


    override fun getDelegateClass(): Class<SubmitPingJiaActivityDelegate> {
        return SubmitPingJiaActivityDelegate::class.java
    }

    override fun getDataBinder(): BaseDataBinder<*, *> {
        return ManagerBaseBinder()
    }

    override fun getData(obj: BaseResponseObj<*>?) {
        super.getData(obj)
        when (obj) {
            is SubmitUnitReportResponseObj -> {
                LKToastUtil.showToastShort("评价成功")
                setResult(101)
                finish()
            }
        }
    }


}